/**
 * Created by litch on 2017/7/14.
 */
import React from 'react'
class Table extends React.Component {
    createThead(heads = []) {
        return (
            <thead>
            <tr>
                {
                    heads.map(function (head) {
                        return <th key={head.key}>{head.name}</th>
                    })
                }
            </tr>
            </thead>
        );
    }

    createTbody(heads = [],data = [], call) {
        return (
            <tbody>
            {
                data.map(function (item,i) {
                    return (
                        <tr key={i}>
                            {
                                heads.map(function (head) {
                                    console.info(head);
                                    return (
                                        <td key={head.key}>{call}</td>
                                    );
                                })
                            }
                        </tr>
                    );
                })
            }
            </tbody>
        );
    }

    render() {
        const {
            heads = [],
            data = []
        } = this.props;
        console.log(heads);
        return (
            <div className="table-responsive">
                <table className="table panel-table table-striped">
                    {this.createThead(heads)}
                    {this.createTbody(heads,data)}
                </table>
            </div>
        );
    }
}
export default Table;